#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *mergeAlternately(char *word1, char *word2)
{
    int n1 = strlen(word1), n2 = strlen(word2);
    int i = 0, j = 0, k = 0;
    char *res = (char *)calloc((n1 + n2 + 1), sizeof(char));
    while (i < n1 || j < n2) {
        if (i < n1) {
            res[k++] = word1[i++];
        }
        if (j < n2) {
            res[k++] = word2[j++];
        }
    }
    return res;
}

void testMergeAlternately(const char *test_name, const char *word1, const char *word2, const char *expected_result)
{
    char *result = mergeAlternately((char *)word1, (char *)word2);
    if (strcmp(result, expected_result) == 0) {
        printf("%s passed.\n", test_name);
    } else {
        printf("%s failed. Expected: %s, Actual: %s\n", test_name, expected_result, result);
    }
    free(result);
}

int main()
{
    testMergeAlternately("Test Case 1", "abc", "pqr", "apbqcr");
    testMergeAlternately("Test Case 2", "ab", "pqrs", "apbqrs");
    testMergeAlternately("Test Case 3", "abcd", "pq", "apbqcd");
}